package pl.elka.simulator.gui.swt.painting;

import java.util.List;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import pl.elka.simulator.core.IPaintable;
import pl.elka.simulator.core.Pair;
import pl.elka.simulator.core.Position;
import pl.elka.simulator.gui.swt.PositionConverter;
import pl.elka.simulator.mediator.ConstraintParts;

public class ConstraintPartsPainter implements IElementPainter{
private Color paintingColor = null;
	
	@Override
	public void paint(IPaintable paintable,PaintEvent e) {		
		GC gc = e.gc;
		if(paintingColor==null){
			paintingColor = new Color(e.display,0,0,0);
		}
	    gc.setForeground(paintingColor);
		
		List<Position> parts = ((ConstraintParts)paintable).getParts();
		int[] pointArray = new int[parts.size()*2];
		int i=0;
		for(Position p:parts){
			Pair<Integer,Integer> converted = PositionConverter.convertFromPosition(p);
			pointArray[i++] = converted.left;
			pointArray[i++] = converted.right;				
		}
		gc.drawPolyline(pointArray);
	}

}
